package com.gitee.cirnochat.common.model.vo.resp;


import com.gitee.cirnochat.chatai.model.enums.aimessage.StreamEventType;
import com.gitee.cirnochat.chatai.model.vo.resp.AIChatSessionVo;
import com.gitee.cirnochat.chatai.model.vo.resp.AISteamDoneVo;
import com.gitee.cirnochat.chatai.model.vo.resp.AiChatSessionMessageVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Schema(description = "流式数据对象")
@AllArgsConstructor
@NoArgsConstructor
public class StreamData<T> implements Serializable {
    @Schema(description = "数据")
    private T data;
    @Schema(description = "事件类型")
    private StreamEventType event;
    
    // 链式设置方法
    public StreamData<T> streamData(T data) {
        this.data = data;
        return this;
    }

    public StreamData<T> event(StreamEventType event) {
        this.event = event;
        return this;
    }

    // 创建数据流消息（使用DATA事件）
    public static <T> StreamData<T> data(T data) {
        return new StreamData<>(data, StreamEventType.DATA);
    }

    // 创建数据流消息（指定事件类型）
    public static <T> StreamData<T> data(T data, StreamEventType event) {
        return new StreamData<>(data, event);
    }

    // 创建插入会话消息
    public static  StreamData<AIChatSessionVo> createSession(AIChatSessionVo data) {
        return new StreamData<>(data, StreamEventType.CREATE_SESSION);
    }

    // 创建更新会话消息
    public static StreamData<AIChatSessionVo> updateSession(AIChatSessionVo data) {
        return new StreamData<>(data, StreamEventType.UPDATE_SESSION);
    }

    // 创建更新消息消息
    public static StreamData<AiChatSessionMessageVo> updateMessage(AiChatSessionMessageVo data) {
        return new StreamData<>(data, StreamEventType.UPDATE_MESSAGE);
    }

    // 创建消息结束消息
    public static StreamData<AISteamDoneVo> done(AISteamDoneVo data) {
        return new StreamData<>(data, StreamEventType.DONE);
    }

    // 创建错误消息
    public static <T> StreamData<T> error(T data) {
        return new StreamData<>(data, StreamEventType.DATA);
    }

    // 创建错误消息（指定事件类型）
    public static <T> StreamData<T> error( T data, StreamEventType event) {
        return new StreamData<>(data, event);
    }
}
